<!--
 * @Description:
 * @Author: ZachGmy
 * @Date: 2020-09-03 09:57:40
 * @LastEditors: 黄悦 9187793+love-to-eat-hot-fried-chicken@user.noreply.gitee.com
 * @LastEditTime: 2022-06-29 11:24:46
-->
<template>
  <div style="position: relative">
    <router-link to="/data/input">
      <i
        class="el-icon-edit"
        style="
          font-size: 50px;
          position: fixed;
          display: inline-block;
          right: 100px;
          bottom: 70px;
        "
      ></i>
    </router-link>
    <el-table
      :data="tableData"
      style="width: 100%"
      :header-cell-style="changeTable"
      :cell-style="changeTable"
      :row-style="changeRow"
    >
      <el-table-column prop="arrayId" label="序号" width="50" height="50">
      </el-table-column>
      <el-table-column prop="country" label="国" width="80"> </el-table-column>
      <el-table-column prop="province" label="省" width="80">
      </el-table-column>
      <el-table-column prop="city" label="市" width="80"> </el-table-column>
      <el-table-column prop="area" label="区" width="80"> </el-table-column>
      <el-table-column prop="confirmed" label="新增确诊" width="80">
      </el-table-column>
      <el-table-column prop="suspected" label="疑似" width="80">
      </el-table-column>
      <el-table-column prop="dead" label="死亡" width="80"> </el-table-column>
      <el-table-column prop="cure" label="治愈" width="80"> </el-table-column>
      <el-table-column prop="severe" label="重症" width="80"> </el-table-column>
      <el-table-column prop="outside" label="境外输入" width="80">
      </el-table-column>
      <el-table-column prop="inputTime" label="上报时间" min-width="150"> </el-table-column>
      <el-table-column
      label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.row.id)">删除</el-button>
      </template>
    </el-table-column>
    </el-table>
    <el-pagination layout="prev, pager, next" :total="tot" :page-size="30" :current-page="currentPage" @current-change="changePage">
    </el-pagination>
  </div>
</template>

<script>
import { get } from "@/utils/request";

export default {
  data() {
    return {
      tableData: null,
      currentPage: 1,
      tot: 0,
    };
  },
  methods: {
    changeTable(options) {
      if (options.columnIndex > 4)
        return "text-align:center;padding:4px 0px; font-size:13px";
      return "font-size:13px;padding:4px 0px";
    },
    changeRow(options) {
      return "line-height:10px;height:10px;";
    },
    handleDelete(id) {

      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            get("/epidemic/deleteById?id="+id).then(()=>{
              
                this.$message({
                  type: 'success',
                  message: '删除成功!'
                });
                this.changePage(this.currentPage);
            })
           
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });

        
    },
    changePage(index) {
      console.log(index)
      let param = {
        page:this.currentPage,
        pageSize:30
      }
      get("/epidemic/pageQuery",param).then((data) => {
          console.log(99999,data)
          this.tot = data.data.total;
          this.tableData = data.data.list;
          for (let i = 0; i < this.tableData.length; i++) {
            this.tableData[i].arrayId = i + 1;
            this.tableData[i].inputTime = fmtdate(this.tableData[i].inputTime);
          }
          console.log(data.data.list);
        });
    },
  },
  mounted() {
    let param = {
      page:this.currentPage,
      pageSize:30
    }
    get( "/epidemic/pageQuery",param).then((data) => {
        console.log(data)
        this.tot = data.data.total;
        this.tableData = data.data.list;
        for (let i = 0; i < this.tableData.length; i++) {
          this.tableData[i].arrayId = i + 1;
          this.tableData[i].inputTime = fmtdate(this.tableData[i].inputTime);
        }
      });
  },
};
import moment from "moment";
function fmtdate(date) {
  return date ? moment(date).format("YYYY-MM-DD HH:mm") : "";
}
function getCookie(name) {
  let matches = document.cookie.match(
    new RegExp(
      "(?:^|; )" +
        name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, "\\$1") +
        "=([^;]*)"
    )
  );
  return matches ? decodeURIComponent(matches[1]) : undefined;
}
</script>
<style scoped>
.uploadButton {
  height: 20px;
  width: 40px;
  font-size: 12px;
  background-color: beige;
  border: none;
}
</style>
